import math
a=str(input())
w=int(a)
q=0
if len(a)!=4 or w<0:
    print(0)
g=a[0]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    q=v
g=a[1]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    n=v
    if n>q:
        q=n
g=a[2]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    m=v
    if m>q:
        q=m
g=a[3]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    z=v
    if z>q:
        q=z

g=a[0] + a[1]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    y=v
    if y>q:
        q=y
g=a[0] + a[1] + a[2]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    l = v
    if l > q:
        q = l
g=a[0] + a[1] + a[2] + a[3]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    s = v
    if s > q:
        q = s

g=a[1] + a[2]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    k = v
    if k > q:
        q = k
g=a[1] + a[2] + a[3]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    x = v
    if x > q:
        q = x
g=a[2] + a[3]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    f = v
    if f > q:
        q = f
if q == 0:
    print(0)
else:
    print(q)
